package com.questionnaires.service;

import com.questionnaires.exception.NotExistsException;
import com.questionnaires.exception.NotUniqueException;
import com.questionnaires.model.User;
import com.questionnaires.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Service for handling user related business operations.
 *
 * @author ioana.ruca@gmail.com
 */
@Service(value = "userService")
public class UserServiceImpl implements UserService {

    @Autowired
    UserRepository userRepository;

    public void saveOrUpdate(User user) throws NotUniqueException {

        userRepository.saveOrUpdate(user);
    }

    @Override
    public List<User> findAll() {

        return userRepository.findAll();
    }

    @Override
    public void deleteById(Long id) throws NotExistsException {

        userRepository.deleteById(id);
    }

    @Override
    public User findByName(String username) {

        return userRepository.findByName(username);
    }
}
